package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.entity.ShelvesStockStatisticsEntity;
import io.renren.modules.sys.entity.TransactionAnalysisEntity;
import io.renren.modules.sys.entity.TransactionAnalysisStatisticsEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.TransactionEntity;
import io.renren.modules.sys.service.TransactionService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-03-27 11:23:52
 */
@RestController
@RequestMapping("sys/transaction")
public class TransactionController {
    @Autowired
    private TransactionService transactionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:transaction:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = transactionService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/getAnalysisList")
    @RequiresPermissions("sys:transaction:getAnalysisList")
    public R getAnalysisList(@RequestParam Map<String, Object> params){
        List<TransactionAnalysisEntity> list = transactionService.getAnalysisList(params);

        return R.ok().put("list", list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:transaction:info")
    public R info(@PathVariable("id") Integer id){
        TransactionEntity transaction = transactionService.getById(id);

        return R.ok().put("transaction", transaction);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:transaction:save")
    public R save(@RequestBody TransactionEntity transaction){
        transactionService.save(transaction);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:transaction:update")
    public R update(@RequestBody TransactionEntity transaction){
        ValidatorUtils.validateEntity(transaction);
        transactionService.updateById(transaction);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:transaction:delete")
    public R delete(@RequestBody Integer[] ids){
        transactionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 统计信息
     */
    @RequestMapping("/infoStatistics")
    @RequiresPermissions("sys:transaction:infoStatistics")
    public R infoStatistics(@RequestParam Map<String, Object> params){
        TransactionAnalysisStatisticsEntity transaction = transactionService.getStatistics(params);

        return R.ok().put("transaction", transaction);
    }

}
